#include <cstdio>
typedef struct{
    long long id;
    int test;
    int real;
}info_t;
int main()
{
    int num1,num2;
    info_t sinfo[1000];
    int tes;
    scanf("%d",&num1);
    int i;
    for(i=0;i<num1;++i)
    {
        scanf("%lld%d%d",&sinfo[i].id,&sinfo[i].test,&sinfo[i].real);
    }
    scanf("%d",&num2);
    while(num2--)
    {
        scanf("%d",&tes);
        for(i=0;i<num1;++i)
        {
            if(sinfo[i].test==tes)
            {
                printf("%lld %d\n",sinfo[i].id,sinfo[i].real);
                break;
            }
        }
    }
}
